package com.pindao.data.controller;

import com.pindao.data.common.Result;
import com.pindao.data.service.ApiDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author LXB
 * @date 2021/4/22
 * @desc
 */
@RestController
@RequestMapping("/data")
@Slf4j
public class ApiDataController {

    @Resource
    private ApiDataService apiDataService;

    /**
     * 接收http
     *
     * @return
     */
    @PostMapping("/req")
    public Result saveReqData(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) {

        log.info("req data == {}", ">>>>>");
        if (paramsMap == null || paramsMap.isEmpty()) {
            return Result.fail("参数为空");
        }
        try {
            return apiDataService.saveReqData(request, paramsMap);
        } catch (Exception e) {
            log.error("error", e);
        }
        return Result.fail();
    }

}
